package com.winbaoxian.testng.platform.controller;

import com.winbaoxian.testng.platform.model.common.JsonResult;
import com.winbaoxian.testng.platform.model.common.Pagination;
import com.winbaoxian.testng.platform.model.common.PaginationDTO;
import com.winbaoxian.testng.platform.model.dto.IdParamDTO;
import com.winbaoxian.testng.platform.model.dto.PlatformProjectDTO;
import com.winbaoxian.testng.platform.service.ProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author dongxuanliang252
 * @date 2019-03-19 17:37
 */
@RestController
@RequestMapping(value = "/project")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    /**
     * @api {POST} /project/save 新增/修改项目信息
     * @apiVersion 1.0.0
     * @apiGroup ProjectController
     * @apiName save
     * @apiParam (请求体) {Number} id 主键
     * @apiParam (请求体) {String} name 名称
     * @apiParam (请求体) {Boolean} integrationFlag 集成状态，true：是 ; false：否
     * @apiParam (请求体) {String} description 描述
     * @apiParamExample 请求体示例
     * {"integrationFlag":false,"name":"x","description":"s","id":8012}
     * @apiSuccess (响应结果) {Number} code 200 成功， 400 失败
     * @apiSuccess (响应结果) {String} msg 提示信息
     * @apiSuccess (响应结果) {Object} data 数据
     * @apiSuccessExample 响应结果示例
     * {"msg":"iq","code":894,"data":{}}
     */
    @PostMapping(value = "save")
    public JsonResult save(@RequestBody PlatformProjectDTO dto) {
        projectService.save(dto);
        return JsonResult.createSuccessResult("操作成功");
    }


    /**
     * @api {GET} /project/page 分页获取项目列表
     * @apiVersion 1.0.0
     * @apiGroup ProjectController
     * @apiName page
     * @apiParam (请求参数) {String} name 名称，支持模糊查询
     * @apiParam (请求参数) {Boolean} integrationFlag 集成状态，true：是 ; false：否
     * @apiParam (请求参数) {Number} pageNum 第几页
     * @apiParam (请求参数) {Number} pageSize 每页数量
     * @apiParamExample 请求参数示例
     * integrationFlag=false&name=tYJhskD&pageSize=5541&pageNum=1840
     * @apiSuccess (响应结果) {Number} code 200 成功， 400 失败
     * @apiSuccess (响应结果) {String} msg 提示信息
     * @apiSuccess (响应结果) {Object} data 数据
     * @apiSuccess (响应结果) {Array} data.list 列表
     * @apiSuccess (响应结果) {Number} data.list.id 主键
     * @apiSuccess (响应结果) {Number} data.list.createTime 创建时间
     * @apiSuccess (响应结果) {Number} data.list.updateTime 更新时间
     * @apiSuccess (响应结果) {String} data.list.name 名称
     * @apiSuccess (响应结果) {Boolean} data.list.integrationFlag 集成状态，true：是 ; false：否
     * @apiSuccess (响应结果) {String} data.list.description 描述
     * @apiSuccess (响应结果) {Number} data.pageNum 第几页
     * @apiSuccess (响应结果) {Number} data.pageSize 每页数量
     * @apiSuccess (响应结果) {Number} data.totalRow 总数
     * @apiSuccess (响应结果) {Number} data.totalPage 总页数
     * @apiSuccess (响应结果) {String} data.orderProperty 排序字段
     * @apiSuccess (响应结果) {String} data.orderDirection 排序方式, DESC 降序;ASC 升序
     * @apiSuccessExample 响应结果示例
     * {"msg":"B06V","code":1446,"data":{"totalRow":5696,"totalPage":5314,"pageSize":9356,"orderDirection":"Z8","list":[{"createTime":905228910643,"integrationFlag":true,"name":"xhW7q","description":"cQtQuT","updateTime":3494789851443,"id":4924}],"pageNum":6738,"orderProperty":"9UE3LXCyj"}}
     */
    @GetMapping(value = "page")
    public JsonResult<PaginationDTO<PlatformProjectDTO>> page(String name, Boolean integrationFlag, Pagination pagination) {
        return JsonResult.createSuccessResult(projectService.page(name, integrationFlag, pagination));
    }

    /**
     * @api {POST} /project/delete 删除项目
     * @apiVersion 1.0.0
     * @apiGroup ProjectController
     * @apiName delete
     * @apiParam (请求体) {Number} id 主键
     * @apiParamExample 请求体示例
     * {"id":6971}
     * @apiSuccess (响应结果) {Number} code 200 成功， 400 失败
     * @apiSuccess (响应结果) {String} msg 提示信息
     * @apiSuccess (响应结果) {Object} data 数据
     * @apiSuccessExample 响应结果示例
     * {"msg":"操作成功","code":200,"data":{}}
     */
    @PostMapping(value = "delete")
    public JsonResult delete(@RequestBody IdParamDTO paramDTO) {
        projectService.delete(paramDTO.getId());
        return JsonResult.createSuccessResult("操作成功");
    }

}
